﻿using System;

namespace CollegeSim.CourseScheduler.Domain.Entities
{
    // Author: Ryan Redburn
    // Project: Course Scheduler
    // Date: 2/4/2014

    public class Course
    {
        #region [ Fields ]

        private int _id;
        private string _crn;
        private string _subject;
        private string _courseNumber;
        private string _title;
        private int _creditHours;
        private int _contactHours;

        #endregion

        #region [ Properties ]

        // Course Identifier
        // Set by DB
        public int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        // CRN
        // Cannot be null or empty and must be four characters in length
        public string CRN
        {
            get { return _crn; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length == 4)
                    {
                        _crn = value;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "CRN must be four characters in length.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "CRN cannot be null or exmpty.");
                }
            }
        }

        // Course Subject
        // Cannot be null or empty and must be three characters in length
        // Format: CIT
        public string Subject
        {
            get { return _subject; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length == 3)
                    {
                        _subject = value.ToUpper();
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "Subject must be three characters in length.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "Subject cannot be null or exmpty.");
                }
            }
        }

        // Course Number
        // Cannot be null or empty and must be three characters in legnth
        public string CourseNumber
        {
            get { return _courseNumber; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length == 3)
                    {
                        _courseNumber = value;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "CourseNumber must be three characters in length.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "CourseNumber cannot be null or exmpty.");
                }
            }
        }

        // Course Title
        // Cannot be null or empty
        public string Title
        {
            get { return _title; }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    if (value.Length <= 50)
                    {
                        _title = value;
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException("value", "Title cannot be more than fifty characters in legnth.");
                    }
                }
                else
                {
                    throw new ArgumentNullException("value", "Title cannot be null or empty.");
                }
            }
        }

        // Course Credits
        public int CreditHours
        {
            get { return _creditHours; }
            set
            {
                if (value >= 1 && value <= 6)
                {
                    _creditHours = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("value", "CreditHours cannot be less than 1 or greater than 6.");
                }
            }
        }

        // Course Contact Hours
        public int ContactHours
        {
            get { return _contactHours; }
            set
            {
                if (value >= 1 && value <= 6)
                {
                    _contactHours = value;
                }
                else
                {
                    throw new ArgumentOutOfRangeException("value", "ContactHours cannot be less than 1 or greater than 6.");
                }
            }
        }

        // Course Style
        public bool IsOnline { get; set; }

        // The Id of the instructor
        public int InstructorId { get; set; }

        #endregion

        #region [ Constructors ]

        public Course()
        {
            _id = 0;
        }

        #endregion

        #region [ Methods ]

        // Overrided ToString() returns basic course information
        public override string ToString()
        {
            return CRN + " - " + Subject + CourseNumber + " - " + Title;
        }

        #endregion
    }
}
